$pageTitle="Visualizations :: Timelines :: Browse Timelines";
include($_SERVER['DOCUMENT_ROOT'] . "/template/header.php");
function format_display_date($y, $m, $d){
//if the month and day are both 1 then we ONLY show the year
if($m==1 && $d==1) return "$y";
//if the month is other than 1 and the day is one we dispay the month as well
if($m>1 && $d==1) return date("M", mktime(0, 0, 0, $m, 1, 2005)) . " " .$y;
//if the day is other than 1 we show the full date
if($d>1) return date("M", mktime(0, 0, 0, $m, 1, 2005)) . " $d, $y";
return false;
}
function display_alert_box($displayString=false, $goodBad="bad"){
$goodBad=strtolower($goodBad);
if($displayString && strlen($displayString)>=1 && ($goodBad=="good" || $goodBad=="bad")){
if($goodBad=="good"){
echo "
\n";
}
else{
echo "\n";
}
}
else{
return false;
}
}
//a boolean that decides whether any search results were found so we can determine whether to let them add to a timeline
$searchResultsFound=false;
//we need to check for any variables submitted
if( isset($_GET['terms']) ){
//something was searched for
$terms = $_GET['terms'];
if( strlen($terms)>=2 && strlen($terms)<=255 && is_string($terms) ){
$terms=sanitize(trim($terms));
//the terms are legit, so now we decide how to sort the results
if( isset($_GET['sort']) ){ $sort=$_GET['sort']; } else{ $sort="ORDER BY score ASC"; }
if($sort=="az"){ $sort="ORDER BY title ASC"; }
elseif($sort=="za"){ $sort="ORDER BY title DESC"; }
elseif($sort=="old"){ $sort="ORDER BY created ASC"; }
elseif($sort=="new"){ $sort="ORDER BY created DESC"; }
elseif($sort=="con"){ $sort="ORDER BY contributor DESC"; }
else{ $sort="ORDER BY score ASC"; }
//run the typical query
$sqlQuery="SELECT id, title, description, contributor, created, MATCH(title, description) AGAINST ('$terms') AS score FROM Timelines WHERE MATCH(title, description) AGAINST ('$terms') OR title='$terms' $sort LIMIT 50";
}
else{
$errorMessage[]="Something is wrong with your search terms. The terms must be words between 2 and 255 letters long.";
}
}
elseif( isset($_GET['special']) ){
//now that sorting is done we can go ahead and search
$special=$_GET['special'];
//run the special
if( $special=="new" ){
$sqlQuery="SELECT id, title, description, contributor, created FROM Timelines ORDER BY created DESC LIMIT 25";
}
else{
//run the typical query
$sqlQuery="SELECT id, title, description, contributor, created, MATCH(title, description) AGAINST ('$terms') AS score FROM Timelines WHERE MATCH(title, description) AGAINST ('$terms') OR title='$terms' $sort LIMIT 50";
}
}
else{
//they didn't give us any terms so we don't need to do anything but give instructions
$sqlQuery=false;
}
?>
Browse Timelines
if( count($errorMessage)>=1 ){
//display any error messages we may have generated
foreach($errorMessage as $error){
display_alert_box($error, "bad");
}
}
else{
//no errors so we can show results
if($sqlQuery){
//echo "
" . $sqlQuery . "
\n";
$result=database_query($sqlQuery);
if( $result && mysql_num_rows($result) ){
//display any extra messages we need to
if($special=="new"){ display_alert_box("Viewing the 25 newest timelines.", "good"); }
//we got results from the search
while($myrow=mysql_fetch_row($result)){
if(strlen($myrow[2])>300){ $previewText=substr($myrow[2], 0, 300) . "..."; } else { $previewText=$myrow[2]; }
echo "
$myrow[1]
\n";
echo "Contributed by $myrow[3]
\n";
}
}
else{
//we did not get results from the search
}
}
else{
echo "
Perform a search to see what timelines are available.
\n";
}
}
?>
include($_SERVER['DOCUMENT_ROOT'] . "/template/footer.php"); ?>